package com.etoak.common.core.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO<T> {

    /**
     * 响应码
     */
    private Integer code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应结果
     */
    private T data;

    /**
     * 接口执行成功后默认的响应码
     */
    public static final int SUCCESS_CODE = 200;

    /**
     * 接口执行成功后默认的响应消息
     */
    public static final String SUCCESS_MESSAGE = "success";

    /**
     * 执行失败后，默认响应码
     */
    public static final int FAILED_CODE = 500;

    /**
     * 未捕获的异常
     */
    public static final String FAILED_MESSAGE = "系统异常！";

    public static final int HTTP_METHOD_NOT_SUPPORT_CODE = 405;

    public static final String HTTP_METHOD_NOT_SUPPORT_MESSAGE = "请求方法错误！";

    public static final int HTTP_MEDIA_TYPE_NOT_SUPPORT_CODE = 415;

    public static final String HTTP_MEDIA_TYPE_NOT_SUPPORT_MESSAGE = "请求参数类型错误！";


    /**
     * 添加、更新、删除接口
     */
    public static <T> ResultVO<T> success() {
        return success(null);
    }

    /**
     * 查询等需要返回数据的接口调用
     */
    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    /**
     * 默认返回 500 系统异常
     */
    public static <T> ResultVO<T> failed() {
        return failed(FAILED_MESSAGE);
    }

    /**
     * 仅自定义错误消息
     */
    public static <T> ResultVO<T> failed(String message) {
        return failed(FAILED_CODE, message);
    }

    /**
     * 自定义错误码和错误消息
     */
    public static <T> ResultVO<T> failed(int code, String message) {
        return new ResultVO<>(code, message, null);
    }
}
